﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using SmartMD.DataAccess.Oracle;
using SmartMD.DataModel.Entity;

namespace SmartMD.Manager.Patient
{
    /// <summary>
    /// Interaction logic for PatientInfoQueryDialog.xaml
    /// </summary>
    public partial class PatientInfoQueryDialog : Window
    {
        public PatientInfoQueryDialog()
        {
            InitializeComponent();
        }


        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            bool isChecked = false;
            //patientList.Clear();

            StringBuilder sb = new StringBuilder();
            sb.Clear();
            sb.Append(" select t.name, t.clinicno, t.DIAGNOSE, t.sex, t.age, t.BIRTHDAY, t.BEDNO, t.HOSPITALNO");
            sb.Append(" from DUO_PATIENT t");


            if (this.cbName.IsChecked == true)
            {
                if (!isChecked)
                    sb.Append(" where");
                else
                    sb.Append(" add");
                String txtName = this.txtName.Text;
                sb.Append(" t.name = '" + txtName + "'");
                isChecked = true;

            }
            if (this.cbClinic.IsChecked == true)
            {
                if (!isChecked)
                    sb.Append(" where");
                else
                    sb.Append(" add");
                String txtClinicNo = this.txtClinic.Text;
                sb.Append(" t.clinicno = '" + txtClinicNo + "'");
                isChecked = true;

            }

            if (this.cbDisType.IsChecked == true)
            {
                if (!isChecked)
                    sb.Append(" where");
                else
                    sb.Append(" add");
                String txtDisType = this.txtDisType.Text;
                sb.Append(" and t.DIAGNOSE = '" + txtDisType + "'");
                isChecked = true;
            }

            DataTable dt = ConnectDatabase.getInstance().Select(sb.ToString());
            PatientInfo item = null;
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    item = new PatientInfo();
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        string clmName;
                        clmName = dt.Columns[i].ColumnName;
                        item.setValue(clmName, dt.Rows[j][clmName]);
                    }
                   // patientList.Add(item);
                }
            }
            else
            {
                MessageBox.Show("未查询到匹配信息，请检查查询条件！", "提示信息", MessageBoxButton.OK, MessageBoxImage.Error);

            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.txtClinic.Text = "";
            this.txtDisType.Text = "";

            this.txtName.Text = "";

        }
    }
}
